﻿RoleInput = Class.create();

RoleInput.prototype = Object.extend(new Common(), {
    initialize: function () {
        this.initCommonProperty();
    },
    init: function () {
        //保存处理
        Event.observe($(this.dom.btnSave), 'click', this.onClick_Save.bind(this));

        //关闭处理
        Event.observe($(this.dom.btnClose), 'click', this.onClick_Close.bind(this));
    },
    //关闭按钮处理
    onClick_Close: function () {
        this.hide();
    },
    //show出画面
    show: function (role_id, callback) {
        $("addRoleInputFrame").style.display = '';

        this.clearForm(this.dom.clientID);

        if (role_id == null) {
            $(this.dom.role_id).value = 0;
            //show出画面
            CmnDialog.show($("addRoleInputFrame"), "添加角色", true);
        }
        else {
            //show出画面
            CmnDialog.show($("addRoleInputFrame"), "编辑角色", true);
            this.getRoleInfo(role_id);
        }
        this.callback = callback;
    },
    getRoleInfo: function (role_id) {
        var data = {};
        data.role_id = role_id;
        this.sendAjaxByModel("/Master/GetRoleInfoByRoleId", data, this.getRoleInfoCallback.bind(this));
    },
    getRoleInfoCallback: function (response) {
        var json = this.jsonParse(response);
        if (json != null) {
            //把json的值赋给画面
            this.initInputForm(json[0], this.dom.clientID);
        }
    },
    //点击关闭是隐藏画面
    hide: function () {
        CmnDialog.hide($("addRoleInputFrame"));
    },
    //保存処理
    onClick_Save: function () {
        //画面保存时弹出确认框
        CmnMessage.showMessage("是否确定提交处理？", MSG_TYPE_CONFIRM, this.saveData.bind(this));
    },
    //保存数据
    saveData: function () {
        this.inputModel = this.getModelByCssClass(this.inputModel, "", this.dom.clientID);

        this.sendAjaxByModel("/Master/SaveRoleInfo", this.inputModel, this.saveDataCallback.bind(this));
    },
    //保存后CallBack
    saveDataCallback: function (response) {
        var json = this.jsonParse(response);
        if (json.result > 0) {
            CmnMessage.showMessage(json.message, MSG_TYPE_INFO, this.messageCallBack.bind(this));
        }
        else {
            CmnMessage.showMessage(json.message, MSG_TYPE_ERROR);
        }
    },
    //画面弹出Message框点击确定或取消后处理
    messageCallBack: function () {
        CmnDialog.hide($("addRoleInputFrame"));

        if (typeof this.callback == "function") {
            this.callback();
        }
    }
});